<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link href="/resource/css/assets/bootstrap.min.css" rel="stylesheet"/>
    <link href="/resource/css/style.css" rel="stylesheet"/>
    <link href="/resource/css/assets/codemirror.css" rel="stylesheet">
    <link rel="stylesheet" href="/resource/css/assets/ace.min.css"/>
    <link rel="stylesheet" href="/resource/font/css/font-awesome.min.css"/>
    <!--[if lte IE 8]>
    <link rel="stylesheet" href="/resource/css/assets/ace-ie.min.css"/>
    <![endif]-->
    <script src="/resource/js/jquery-1.9.1.min.js"></script>
    <script src="/resource/js/assets/bootstrap.min.js"></script>
    <script type="text/javascript" src="/resource/js/Validform.min.js"></script>
    <script src="/resource/js/assets/typeahead-bs2.min.js"></script>
    <script src="/resource/js/lrtk.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/resource/common/layui/css/layui.css" media="all"/>
    <title>管理权限</title>
</head>

<body>
<div class="margin clearfix">
    <div class="border clearfix">
       <span class="l_f">
        <a id="Competence_add" class="btn btn-warning addRole" title="添加权限"><i class="fa fa-plus"></i> 添加角色</a>
       </span>
    </div>
    <div class="compete_list">
        <table id="roleTables" data-mobile-responsive="true" lay-filter="roleTables"></table>
    </div>
</div>
<script type="text/html" id="operate">
    <a title="编辑" class="btn btn-xs btn-info" lay-event="edit" style="padding: 0px 10px"><i
            class="fa fa-edit bigger-120"></i></a>
    <a title="删除" class="btn btn-xs btn-warning" lay-event="del" style="padding: 0px 10px"><i
            class="fa fa-trash  bigger-120"></i></a>
    <a title="授权" class="btn btn-xs btn-warning" lay-event="accredit" style="padding: 0px 10px">
        <i class="fa layui-icon layui-icon-auz bigger-120" style="font-size: 12px"></i></a>
</script>
</body>
</html>
<script type="text/javascript" src="/resource/common/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['table', 'layer', 'laydate', 'form'], function () {
        var table = layui.table,
            $ = layui.$,
            layer = layui.layer,
            form = layui.form;

        var tableIns = table.render({
            elem: '#roleTables'
            , even: true
            , url: '/role/role.do' //数据接口
            , method: 'get'
            , page: true //开启分页
            , id: 'tableId'
            , limits: [10, 15, 30]
            , limit: 15
            , cols: [
                [ //表头
                    {'type': 'numbers', title: '序号', 'fixed': 'left'}
                    , {field: 'role', title: '角色名'}
                    , {field: 'description', title: '权限描述'}
                    , {field: 'createName', title: '创建人'}
                    , {title: '操作', toolbar: '#operate', 'fixed': 'right', width: 200}
                ]
            ]
        });
        $('.addRole').on('click', function () {
            layer.open({
                type: 2,
                shadeClose: false, //点击遮罩关闭层
                title: "创建角色",
                area: ['45%', '50%'],
                content: "/role/addRole.do"
            });
        });
        //监听工具条
        table.on('tool(roleTables)', function (obj) {
            var data = obj.data;
            console.log(data);
            if (obj.event === 'del') {
                //删除
                delRole(data.id);
            } else if (obj.event === "edit") {
                //修改
                layer.open({
                    type: 2,
                    shadeClose: false, //点击遮罩关闭层
                    title: "编辑角色",
                    area: ['45%', '50%'],
                    content: "/role/editRole.do?id=" + data.id
                });
            } else if (obj.event === "accredit") {
                //修改
                layer.open({
                    type: 2,
                    shadeClose: false, //点击遮罩关闭层
                    title: "角色授权",
                    area: ['100%', '100%'],
                    content: "/role/accreditRole.do?id=" + data.id
                });
            }
        });
        active = {
            reload: function () {
                console.log(status);
                //执行重载
                table
                    .reload('tableId', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                    });
            }
        };

        //删除角色函数
        function delRole(id) {
            layer.confirm('是否删除?', function (index) {
                $.ajax({
                    url: "/role/role.do",
                    type: "post",
                    data: {_method: "DELETE", "id": id},
                    dataType: "json",
                    success: function (result) {
                        if (!result.status) {
                            layer.msg(result.msg, {time: 2000});
                            return false;
                        }
                        layer.msg("删除成功!", {time: 1000});
                        active.reload();
                    }
                });
                layer.close(index);
            })
        }
    });
</script>
